package com.yutel.tool.web;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class WebThread extends Thread {
	private String url;

	public WebThread(String url) {
		this.url = url;
	}

	@Override
	public void run() {
		URL curl = null;
		InputStream input = null;
		HttpURLConnection conn = null;
		long start = System.currentTimeMillis();
		try {
			curl = new URL(url);
			conn = (HttpURLConnection) curl.openConnection();
			conn.setRequestProperty("Content-Type",
					"application/x-www-form-urlencoded");
			conn.setRequestMethod("GET");
			conn.setConnectTimeout(10000);
			conn.setReadTimeout(20000);
			if (conn.getResponseCode() == 200) {
				input = conn.getInputStream();
				BufferedReader br = new BufferedReader(new InputStreamReader(
						input));
				String info = null;
				while ((info = br.readLine()) != null) {
					info.length();
				}
			} else {
				System.err.println("responseCode=" + conn.getResponseCode());
			}
			long stop = System.currentTimeMillis();
			long timelan = stop - start;
			if (timelan > 10000) {
				System.out.println("alltime=" + timelan);
			}
		} catch (IOException e) {
			long error = System.currentTimeMillis();
			long errortime = error - start;
			System.out.println("errortime=" + errortime);
		} finally {
			if (input != null) {
				try {
					input.close();
				} catch (IOException e) {
				}
			}
		}
	}
}
